<?php
class Model_data extends MY_Model {

	function __construct() {
		parent::__construct();
		$this->aUser = $this->usersession->currentUser();
	}


	function addObject($data, $sTabel) {

		$this->db->where("nom_{$sTabel}.{$sTabel}_nume", $data);
		$dataInsert = array($sTabel.'_nume' => strTitle($data));
		$query = $this->db->get("nom_".$sTabel);

		if ($query->num_rows() > 0) {
			return FALSE;
		} else {
			$this->db->insert("nom_".$sTabel, $dataInsert);
		}

		return TRUE;
	}


	function addFunctieSub($data, $iFunctie) {

		$this->db->where("functie_id", $iFunctie);
		$this->db->where("functie_sub_nume", $data);
		$query = $this->db->get("nom_functie_sub");

		if ($query->num_rows() > 0) {
			return FALSE;
		} else {
			$dataInsert = array('functie_sub_nume' => strTitle($data), "functie_id" => $iFunctie);
			$this->db->insert("nom_functie_sub", $dataInsert);
		}

		return TRUE;
	}

	function addDomeniuSub($data, $iDomeniu) {

		$this->db->where("domeniu_id", $iDomeniu);
		$this->db->where("domeniu_sub_nume", $data);
		$query = $this->db->get("nom_domeniu_sub");

		if ($query->num_rows() > 0) {
			return FALSE;
		} else {
			$dataInsert = array('domeniu_sub_nume' => strTitle($data), "domeniu_id" => $iDomeniu);
			$this->db->insert("nom_domeniu_sub", $dataInsert);
		}

		return TRUE;
	}

	function addCampanie($sData, $iClient, $iTip) {

		$this->db->where("campanie_nume", $sData);
		$this->db->where("client_id", $iClient);
		$query = $this->db->get("nom_campanie");

		if ($query->num_rows() > 0) {
			return FALSE;
		} else {
			$dataInsert = array('campanie_nume' => strTitle($sData), "client_id" => $iClient, "campanie_tip" => $iTip);
			$this->db->insert("nom_campanie", $dataInsert);
		}

		return TRUE;
	}


	function getJudet($aPost) {

		$iStart = (isset($aPost["start"]) && ($aPost["start"] != "")) ? $aPost["start"] : 0;
		$iLimit = (isset($aPost["limit"]) && ($aPost["limit"] != "")) ? $aPost["limit"] : 50;
		$sSort = (isset($aPost["sort"]) && ($aPost["sort"] != "")) ? $aPost["sort"] : "judet_nume";
		$sDir = (isset($aPost["dir"]) && ($aPost["dir"] != "")) ? $aPost["dir"] : "ASC";

		if ($aPost["query"] != "") {
			$this->db->like("judet_nume", $aPost["query"]);
		}
		$this->db->order_by($sSort, $sDir);
		$this->db->limit($iLimit, $iStart);
		$query = $this->db->get("nom_judet");
		$aData = $query->result_array();

		$data = array('totalCount' => 50, 'data' => $aData);

		return $data;
	}

	function getOras($aPost) {

		$iStart = (isset($aPost["start"]) && ($aPost["start"] != "")) ? $aPost["start"] : 0;
		$iLimit = (isset($aPost["limit"]) && ($aPost["limit"] != "")) ? $aPost["limit"] : 50;
		$sSort = (isset($aPost["sort"]) && ($aPost["sort"] != "")) ? $aPost["sort"] : "oras_nume";
		$sDir = (isset($aPost["dir"]) && ($aPost["dir"] != "")) ? $aPost["dir"] : "ASC";

		if ($aPost["query"] != "") {
			$this->db->like("oras_nume", $aPost["query"]);
		}
		$this->db->order_by($sSort, $sDir);
		$this->db->limit($iLimit, $iStart);
		$query = $this->db->get("nom_oras");
		$aData = $query->result_array();

		$data = array('totalCount' => 50, 'data' => $aData);

		return $data;
	}

	function getDepartament($aPost) {

		$iStart = (isset($aPost["start"]) && ($aPost["start"] != "")) ? $aPost["start"] : 0;
		$iLimit = (isset($aPost["limit"]) && ($aPost["limit"] != "")) ? $aPost["limit"] : 50;
		$sSort = (isset($aPost["sort"]) && ($aPost["sort"] != "")) ? $aPost["sort"] : "departament_nume";
		$sDir = (isset($aPost["dir"]) && ($aPost["dir"] != "")) ? $aPost["dir"] : "ASC";

		if ($aPost["query"] != "") {
			$this->db->like("departament_nume", $aPost["query"]);
		}
		$this->db->order_by($sSort, $sDir);
		$this->db->limit($iLimit, $iStart);
		$query = $this->db->get("nom_departament");
		$aData = $query->result_array();

		$data = array('totalCount' => 50, 'data' => $aData);

		return $data;
	}

	function getFunctie($aPost) {

		$iStart = (isset($aPost["start"]) && ($aPost["start"] != "")) ? $aPost["start"] : 0;
		$iLimit = (isset($aPost["limit"]) && ($aPost["limit"] != "")) ? $aPost["limit"] : 50;
		$sSort = (isset($aPost["sort"]) && ($aPost["sort"] != "")) ? $aPost["sort"] : "functie_nume";
		$sDir = (isset($aPost["dir"]) && ($aPost["dir"] != "")) ? $aPost["dir"] : "ASC";

		if ($aPost["query"] != "") {
			$this->db->like("functie_nume", $aPost["query"]);
		}
		$this->db->order_by($sSort, $sDir);
		$this->db->limit($iLimit, $iStart);
		$query = $this->db->get("nom_functie");
		$aData = $query->result_array();

		$data = array('totalCount' => 50, 'data' => $aData);

		return $data;
	}

	function getFunctieSub($aPost) {

		$iStart = (isset($aPost["start"]) && ($aPost["start"] != "")) ? $aPost["start"] : 0;
		$iLimit = (isset($aPost["limit"]) && ($aPost["limit"] != "")) ? $aPost["limit"] : 50;
		$sSort = (isset($aPost["sort"]) && ($aPost["sort"] != "")) ? $aPost["sort"] : "functie_sub_nume";
		$sDir = (isset($aPost["dir"]) && ($aPost["dir"] != "")) ? $aPost["dir"] : "ASC";

		if ($aPost["query"] != "") {
			$this->db->like("functie_sub_nume", $aPost["query"]);
		}

		if ($aPost["functie_id"] != "") {
			$this->db->like("functie_id", $aPost["functie_id"]);
		}

		$this->db->order_by($sSort, $sDir);
		$this->db->limit($iLimit, $iStart);
		$query = $this->db->get("nom_functie_sub");
		$aData = $query->result_array();

		$data = array('totalCount' => 50, 'data' => $aData);

		return $data;
	}

	function getDomeniu($aPost) {

		$iStart = (isset($aPost["start"]) && ($aPost["start"] != "")) ? $aPost["start"] : 0;
		$iLimit = (isset($aPost["limit"]) && ($aPost["limit"] != "")) ? $aPost["limit"] : 50;
		$sSort = (isset($aPost["sort"]) && ($aPost["sort"] != "")) ? $aPost["sort"] : "domeniu_nume";
		$sDir = (isset($aPost["dir"]) && ($aPost["dir"] != "")) ? $aPost["dir"] : "ASC";

		if ($aPost["query"] != "") {
			$this->db->like("domeniu_nume", $aPost["query"]);
		}
		$this->db->order_by($sSort, $sDir);
		$this->db->limit($iLimit, $iStart);
		$query = $this->db->get("nom_domeniu");
		$aData = $query->result_array();

		$data = array('totalCount' => 50, 'data' => $aData);

		return $data;
	}

	function getDomeniuSub($aPost) {

		$iStart = (isset($aPost["start"]) && ($aPost["start"] != "")) ? $aPost["start"] : 0;
		$iLimit = (isset($aPost["limit"]) && ($aPost["limit"] != "")) ? $aPost["limit"] : 50;
		$sSort = (isset($aPost["sort"]) && ($aPost["sort"] != "")) ? $aPost["sort"] : "domeniu_sub_nume";
		$sDir = (isset($aPost["dir"]) && ($aPost["dir"] != "")) ? $aPost["dir"] : "ASC";

		if ($aPost["query"] != "") {
			$this->db->like("domeniu_sub_nume", $aPost["query"]);
		}

		if ($aPost["domeniu_id"] != "") {
			$this->db->like("domeniu_id", $aPost["domeniu_id"]);
		}

		$this->db->order_by($sSort, $sDir);
		$this->db->limit($iLimit, $iStart);
		$query = $this->db->get("nom_domeniu_sub");
		$aData = $query->result_array();

		$data = array('totalCount' => 50, 'data' => $aData);

		return $data;
	}

	function getClient($aPost) {

		$iStart = (isset($aPost["start"]) && ($aPost["start"] != "")) ? $aPost["start"] : 0;
		$iLimit = (isset($aPost["limit"]) && ($aPost["limit"] != "")) ? $aPost["limit"] : 50;
		$sSort = (isset($aPost["sort"]) && ($aPost["sort"] != "")) ? $aPost["sort"] : "client_nume";
		$sDir = (isset($aPost["dir"]) && ($aPost["dir"] != "")) ? $aPost["dir"] : "ASC";

		if ($aPost["query"] != "") {
			$this->db->like("client_nume", $aPost["query"]);
		}
		$this->db->order_by($sSort, $sDir);
		$this->db->limit($iLimit, $iStart);
		$query = $this->db->get("nom_client");
		$aData = $query->result_array();

		$data = array('totalCount' => 50, 'data' => $aData);

		return $data;
	}

	function getCampanie($aPost) {

		$iStart = (isset($aPost["start"]) && ($aPost["start"] != "")) ? $aPost["start"] : 0;
		$iLimit = (isset($aPost["limit"]) && ($aPost["limit"] != "")) ? $aPost["limit"] : 50;
		$sSort = (isset($aPost["sort"]) && ($aPost["sort"] != "")) ? $aPost["sort"] : "campanie_nume";
		$sDir = (isset($aPost["dir"]) && ($aPost["dir"] != "")) ? $aPost["dir"] : "ASC";

		if ($aPost["query"] != "") {
			$this->db->like("campanie_nume", $aPost["query"]);
		}

		if ($aPost["client_id"] != "") {
			$this->db->like("client_id", $aPost["client_id"]);
		}

		$this->db->order_by($sSort, $sDir);
		$this->db->limit($iLimit, $iStart);
		$query = $this->db->get("nom_campanie");
		$aData = $query->result_array();

		$data = array('totalCount' => 50, 'data' => $aData);

		return $data;
	}


}
//end model